<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="spd" tagdir="/WEB-INF/tags/admin/"%>
<spd:layout>

<jsp:attribute name="head">
<!-- html的头部内容，如title、css等。 -->
<title>微信公众号设置</title>
<style type="text/css">
	
</style>
</jsp:attribute>

<jsp:attribute name="body">
<div class="row">
	<div class="col-md-12">
		<div class="callout callout-success">
			<div>请在微信公众平台设置URL为&nbsp;<strong>http://&lt;域名&gt;${pageContext.request.contextPath}/mobile/wechat/api.do</strong></div>
		</div>
	</div>
</div>

<div class="row">
	<div class="col-md-12">
		<div class="box box-primary">
			<div class="box-body">
				<div class="row">
					<div class="col-md-10 col-md-offset-1">
						<form id="form">
							<table class="table table-bordered spd-table">
								<tbody>
									<tr>
										<td style="width: 140px;"><label class="spd-label">公众号名称</label></td>
										<td>
											<div class="spd-validate">
												<input class="form-control" type="text" name="name" placeholder="必填">
											</div>
										</td>
									</tr>
									<tr>
										<td><label class="spd-label">Token</label></td>
										<td>
											<div class="spd-validate">
												<input class="form-control" type="text" name="token" placeholder="必填">
											</div>
										</td>
									</tr>
									<tr>
										<td><label class="spd-label">AppId</label></td>
										<td>
											<div class="spd-validate">
												<input class="form-control" type="text" name="appid" placeholder="必填">
											</div>
										</td>
									</tr>
									<tr>
										<td><label class="spd-label">AppSecret</label></td>
										<td>
											<div class="spd-validate">
												<input class="form-control" type="text" name="appsecret" placeholder="必填">
											</div>
										</td>
									</tr>
									<tr>
										<td><label class="spd-label">消息加密解密</label></td>
										<td>
											<div class="spd-validate">
												<select class="form-control" name="encodingType">
													<option value="0">明文模式</option>
													<!--
													<option value="1">兼容模式</option>
													<option value="2">安全模式</option>
													-->
												</select>
											</div>
										</td>
									</tr>
									<tr>
										<td><label class="spd-label">EncodingAESKey</label></td>
										<td>
											<div class="spd-validate">
												<input class="form-control" type="text" name="encodingAeskey" placeholder="选填">
											</div>
										</td>
									</tr>									
									<tr>
										<td>&nbsp;</td>
										<td>
											<button class="btn btn-primary" id="btnSave" style="width:120px;">保存</button>
											&nbsp;
											<button class="btn btn-primary" id="btnReset" style="width:120px;">重置</button>
											&nbsp;
											<button class="btn btn-default" id="btnClose" style="width:120px;">关闭</button>
										</td>
									</tr>
								</tbody>
							</table>
							<!-- /#table -->
						</form>
						<!-- /#form -->
					</div>
				</div>				
			</div>
			<!-- /.box-body -->
		</div>	
	</div>
</div>
<!-- /.row -->
</jsp:attribute>

<jsp:attribute name="dialog">
<!-- 弹出框内容 -->
</jsp:attribute>

<jsp:attribute name="script">
<script type="text/javascript">
	$(function(){
		SpdUI.getJSON({
			url: SpdUI.contextPath + '/admin/wechat/config/detail.do',
			failure: false,
			success: function(data, json){
				data && SpdUI.objectToForm('#form', data);
			}
		});
		
		$('#btnClose').on('click', function(){
			SpdUI.closeTab('wechatConfig');
			return false;
		});
		
		$('#btnReset').on('click', function(){
			SpdUI.confirm('确定重置微信公众号？', function(){
				SpdUI.getJSON({
					url: SpdUI.contextPath + '/admin/wechat/config/reset.do',
					failure: false,
					success: function(data, json){
						window.location.reload();
					}
				});
			});			
			return false;
		});
		
		SpdUI.formValidator('#form', {
			name: {
				rule: 'required;length(~50)',
				msg: '请输入公众号名称，不超过20个字。'
			},
			token: {
				rule: 'required',
				msg: '必填'
			},
			appid: {
				rule: 'required',
				msg: '必填'
			},
			appsecret: {
				rule: 'required',
				msg: '必填'
			}
		}, 'bottom');
		
		$('#btnSave').on('click', function(){
			var $form = $('#form');
			if(!$form.isValid()) {
				return false;
			}
			
			SpdUI.ajaxSubmit($form, {
				url: SpdUI.contextPath + '/admin/wechat/config/update.do',
				success: function(data, json) {
					SpdUI.alert('操作成功！');					
				}
			});
			
			return false;
		});
	});
</script>
</jsp:attribute>

</spd:layout>